package com.example.shiyan2

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Call
import androidx.compose.material.icons.filled.Email
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.shiyan2.ui.theme.Shiyan2Theme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            Shiyan2Theme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    Greeting(
                        name = "Android",
                        modifier = Modifier.padding(innerPadding)
                    )
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    val img: Painter = painterResource(id = R.drawable.oip_c)


    Row(
        modifier = modifier
            .fillMaxSize()
            .background(Color(0xFFFFC644))
    ) {

        Column(
            modifier = Modifier
                .width(50.dp)
                .fillMaxHeight()
                .padding(start = 10.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            listOf("春", "风", "入", "喜", "财", "入", "户").forEach { char ->
                Text(
                    text = char,
                    style = TextStyle(
                        fontSize = 18.sp,
                        color = Color(0xFF9E2A2B),
                        fontWeight = androidx.compose.ui.text.font.FontWeight.Bold
                    ),
                    modifier = Modifier.padding(2.dp)
                )
            }
        }


        Column(
            verticalArrangement = Arrangement.Top,
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = Modifier
                .weight(1f)
                .fillMaxHeight()
                .padding(top = 50.dp)
        ) {

            Text(
                text = "恭喜发财",
                style = TextStyle(
                    fontSize = 36.sp,
                    color = Color(0xFF9E2A2B),
                    fontWeight = androidx.compose.ui.text.font.FontWeight.Bold,
                    letterSpacing = 2.sp
                ),
                modifier = Modifier.padding(bottom = 30.dp)
            )


            Column(
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier.fillMaxSize()
            ) {

                Image(
                    painter = img,
                    contentDescription = "应用图标背景",
                    alpha = 1F,
                    modifier = Modifier
                        .padding(vertical = 10.dp)
                        .height(100.dp),
                    contentScale = ContentScale.Fit
                )


                Text(
                    text = "$name",
                    textAlign = androidx.compose.ui.text.style.TextAlign.Center,
                    style = TextStyle(
                        fontSize = 50.sp,
                        lineHeight = 50.sp
                    ),
                    modifier = Modifier.padding(vertical = 10.dp)
                )


                Text(
                    text = "新年快乐",
                    style = TextStyle(
                        fontSize = 25.sp,
                        lineHeight = 30.sp
                    ),
                    modifier = Modifier.padding(vertical = 10.dp)
                )

                Spacer(modifier = Modifier.height(50.dp))


                Column(
                    verticalArrangement = Arrangement.Center,
                    horizontalAlignment = Alignment.CenterHorizontally,
                    modifier = modifier
                        .fillMaxWidth()
                        .padding(top = 30.dp)
                ) {
                    Row(
                        horizontalArrangement = Arrangement.Center,
                        verticalAlignment = Alignment.CenterVertically,
                        modifier = Modifier.padding(vertical = 5.dp)
                    ) {
                        Icon(
                            imageVector = Icons.Default.Call,
                            contentDescription = "电话图标",
                            modifier = Modifier.size(30.dp),
                            tint = Color(0xFF9E2A2B)
                        )
                        Text(
                            text = "+110119120",
                            style = TextStyle(
                                fontSize = 20.sp,
                                lineHeight = 20.sp
                            ),
                            modifier = Modifier.padding(start = 8.dp)
                        )
                    }
                    Row {
                        Icon(
                            imageVector = Icons.Default.Email,
                            contentDescription = "邮箱图标",
                            modifier = Modifier.size(30.dp),
                            tint = Color(0xFF9E2A2B)
                        )
                        Text(
                            text = "114514@outlook.com",
                            style = TextStyle(fontSize = 20.sp),
                            modifier = Modifier.padding(start = 8.dp)
                        )
                    }
                }
            }
        }


        Column(
            modifier = Modifier
                .width(50.dp)
                .fillMaxHeight()
                .padding(end = 10.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            listOf("岁", "月", "更", "新", "福", "满", "门").forEach { char ->
                Text(
                    text = char,
                    style = TextStyle(
                        fontSize = 18.sp,
                        color = Color(0xFF9E2A2B),
                        fontWeight = androidx.compose.ui.text.font.FontWeight.Bold
                    ),
                    modifier = Modifier.padding(2.dp)
                )
            }
        }
    }
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    Shiyan2Theme {
        Greeting("张一丁")
    }
}